#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    string reverseStr(string s, int k)
    {
        auto it = s.begin();
        int i = 0;

        while (i < s.size())
        {
            if ((i + 2 * k) < s.size())
            {
                i += 2 * k;
                reverse(it, it + k);
                it += 2 * k;
            }
            else if (i + k < s.size())
            {

                reverse(it, it + k);
                i += k;
                break;
            }
            else
            {
                reverse(it, s.end());
                break;
            }
        }


        return s;

    }
};